package com.yanqu.road.dao.impl.activity.daomu;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.daomu.config.*;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class DaoMuConfigDaoImpl extends TempDao {

    /**
     * 关卡配置
     */
    private static String getDaoMuMissionSql = "select * from `t_s_activity_daomu_mission` where `activityId`=? ORDER BY `id` ASC";
    public Map<Integer, DaoMuMissionConfig> getDaoMuMissionConfig(int activityId) {
        Map<Integer, DaoMuMissionConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getDaoMuMissionSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                DaoMuMissionConfig daoMuMissionConfig = new DaoMuMissionConfig();
                daoMuMissionConfig.setActivityId(rs.getInt("activityId"));
                daoMuMissionConfig.setId(rs.getInt("id"));
                daoMuMissionConfig.setFloor(rs.getInt("floor"));
                daoMuMissionConfig.setMap(rs.getInt("map"));
                daoMuMissionConfig.setChapterName(rs.getString("chapterName"));
                daoMuMissionConfig.setChapterDesc(rs.getString("chapterDesc"));
                daoMuMissionConfig.setName(rs.getString("name"));

                daoMuMissionConfig.setMobsAppearTime(rs.getString("mobsAppearTime"));
                daoMuMissionConfig.setMobsId(rs.getString("mobsId"));
                daoMuMissionConfig.setMobsAppearFrequency(rs.getString("mobsAppearFrequency"));
                daoMuMissionConfig.setMobsEffects(rs.getString("mobsEffects"));

                daoMuMissionConfig.setSpecialMobsAppearTime(rs.getString("specialMobsAppearTime"));
                daoMuMissionConfig.setSpecialMobsId(rs.getString("specialMobsId"));
                daoMuMissionConfig.setSpecialMobsNum(rs.getString("specialMobsNum"));
                daoMuMissionConfig.setSpecialMobsEffects(rs.getString("specialMobsEffects"));

                daoMuMissionConfig.setBossId(rs.getString("bossId"));
                daoMuMissionConfig.setBossAppearTime(rs.getString("bossAppearTime"));
                daoMuMissionConfig.setBossEffects(rs.getString("bossEffects"));

                daoMuMissionConfig.setRewards(rs.getString("rewards"));
                daoMuMissionConfig.setSpecialRewards(rs.getString("specialRewards"));

                daoMuMissionConfig.setBountyMonster(rs.getString("bountyMonster"));
                daoMuMissionConfig.setBountyRewards(rs.getString("bountyRewards"));
                daoMuMissionConfig.setSpecialBountyRewards(rs.getString("specialBountyRewards"));

                daoMuMissionConfig.setNeedFavoriteScore(rs.getInt("needFavoriteScore"));
                daoMuMissionConfig.setPassFavoriteScore(rs.getInt("passFavoriteScore"));

                daoMuMissionConfig.setSpecialGameRewards(rs.getString("specialGameRewards"));
                daoMuMissionConfig.setSpecialBountyGameRewards(rs.getString("specialBountyGameRewards"));

                daoMuMissionConfig.setMobsNumMax(rs.getInt("mobsNumMax"));

                //特色服专用字段
                daoMuMissionConfig.setUnlock(rs.getString("unlock") == null ? "" : rs.getString("unlock"));
                daoMuMissionConfig.setPartnerId(rs.getInt("partnerId"));
                daoMuMissionConfig.setParam(rs.getString("param") == null ? "" : rs.getString("param"));
                daoMuMissionConfig.setSkillList(rs.getString("skillList") == null ? "" : rs.getString("skillList"));

                map.put(daoMuMissionConfig.getId(), daoMuMissionConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * NPC配置
     */
    private static String getDaoMuNpcSql = "select * from `t_s_activity_daomu_npc` where `activityId`=? ORDER BY `id` ASC";
    public Map<Integer, DaoMuNpcConfig> getDaoMuNpcConfig(int activityId) {
        Map<Integer, DaoMuNpcConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getDaoMuNpcSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                DaoMuNpcConfig daoMuNpcConfig = new DaoMuNpcConfig();
                daoMuNpcConfig.setActivityId(rs.getInt("activityId"));
                daoMuNpcConfig.setId(rs.getInt("id"));
                daoMuNpcConfig.setType(rs.getInt("type"));
                daoMuNpcConfig.setBoxFlag(rs.getInt("boxFlag"));
                daoMuNpcConfig.setIcon(rs.getInt("icon"));
                daoMuNpcConfig.setName(rs.getString("name"));
                daoMuNpcConfig.setDesc(rs.getString("desc"));
                daoMuNpcConfig.setBasePara(rs.getString("basePara"));
                daoMuNpcConfig.setSkillId(rs.getString("skillId"));
                daoMuNpcConfig.setSpecialRewards(rs.getString("specialRewards"));
                daoMuNpcConfig.setCollisionSize(rs.getString("collisionSize"));
                daoMuNpcConfig.setBornPara(rs.getString("bornPara"));
                map.put(daoMuNpcConfig.getId(), daoMuNpcConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * 藏品配置
     */
    private static String getDaoMuCurioSql = "select * from `t_s_activity_daomu_curio` where `activityId`=? ORDER BY `id` ASC";
    public Map<Integer, DaoMuCurioConfig> getDaoMuCurioConfig(int activityId) {
        Map<Integer, DaoMuCurioConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getDaoMuCurioSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                DaoMuCurioConfig daoMuCurioConfig = new DaoMuCurioConfig();
                daoMuCurioConfig.setActivityId(rs.getInt("activityId"));
                daoMuCurioConfig.setId(rs.getInt("id"));
                daoMuCurioConfig.setType(rs.getInt("type"));
                daoMuCurioConfig.setQuality(rs.getInt("quality"));
                daoMuCurioConfig.setIcon(rs.getInt("icon"));
                daoMuCurioConfig.setName(rs.getString("name"));
                daoMuCurioConfig.setDesc(rs.getString("desc"));
                daoMuCurioConfig.setFavoriteScore(rs.getInt("favoriteScore"));
                daoMuCurioConfig.setCurioId(rs.getInt("curioId"));
                daoMuCurioConfig.setLevel(rs.getInt("level"));
                daoMuCurioConfig.setCost(rs.getString("cost"));
                daoMuCurioConfig.setBasePara(rs.getString("basePara"));
                daoMuCurioConfig.setUnlockSkillLevel(rs.getString("unlockSkillLevel"));
                daoMuCurioConfig.setAttributePara(rs.getString("attributePara"));
                daoMuCurioConfig.setUnlockCond(rs.getInt("unlockCond"));
                map.put(daoMuCurioConfig.getId(), daoMuCurioConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * 等级配置
     */
    private static String getDaoMuPlayerLevelSql = "select * from `t_s_activity_daomu_player_level` where `activityId`=? ORDER BY `id` ASC";
    public Map<Integer, DaoMuPlayerLevelConfig> getDaoMuPlayerLevelConfig(int activityId) {
        Map<Integer, DaoMuPlayerLevelConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getDaoMuPlayerLevelSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                DaoMuPlayerLevelConfig info = new DaoMuPlayerLevelConfig();
                info.setActivityId(rs.getInt("activityId"));
                info.setId(rs.getInt("id"));
                info.setLevel(rs.getInt("level"));
                info.setCost(rs.getInt("cost"));
                info.setPvpCost(rs.getInt("pvpCost"));
                info.setEndDowngrade(rs.getString("endDowngrade"));
                info.setEndDropsExp(rs.getString("endDropsExp"));
                info.setPvpInitialArmsNum(rs.getInt("pvpInitialArmsNum"));
                info.setEndDropsArmsNum(rs.getString("endDropsArmsNum"));
                map.put(info.getLevel(), info);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * 技能配置
     */
    private static String getDaoMuSkillSql = "select * from `t_s_activity_daomu_skill` where `activityId`=? ORDER BY `id` ASC";
    public Map<Integer, DaoMuSkillConfig> getDaoMuSkillConfig(int activityId) {
        Map<Integer, DaoMuSkillConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getDaoMuSkillSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                DaoMuSkillConfig info = new DaoMuSkillConfig();
                info.setActivityId(rs.getInt("activityId"));
                info.setId(rs.getInt("id"));
                info.setSkillId(rs.getInt("skillId"));
                info.setLevel(rs.getInt("level"));
                info.setName(rs.getString("name"));
                info.setDesc(rs.getString("desc"));
                info.setType(rs.getInt("type"));
                info.setIcon(rs.getInt("icon"));
                info.setSkillPara(rs.getString("skillPara"));
                info.setCombSkill(rs.getInt("combSkill"));
                map.put(info.getId(), info);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * 开棺宝箱配置
     */
    private static String getDaoMuCrowbarBoxSql = "select * from `t_s_activity_daomu_crowbar_box` where `activityId`= ? ORDER BY `id` ASC";
    public Map<Integer, DaoMuCrowbarBoxConfig> getDaoMuCrowbarBoxConfig(int activityId) {
        Map<Integer, DaoMuCrowbarBoxConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getDaoMuCrowbarBoxSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                DaoMuCrowbarBoxConfig info = new DaoMuCrowbarBoxConfig();
                info.setActivityId(rs.getInt("activityId"));
                info.setId(rs.getInt("id"));
                info.setName(rs.getString("name"));
                info.setDesc(rs.getString("desc"));
                info.setCost(rs.getString("cost"));
                info.setItemWeights(rs.getString("itemWeights"));
                info.setCurioWeights(rs.getString("curioWeights"));
                info.setProgressValueAdd(rs.getInt("progressValueAdd"));
                map.put(info.getId(), info);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * 开棺宝箱进度配置
     */
    private static String getDaoMuProgressSql = "select * from `t_s_activity_daomu_progress` where `activityId`= ? ORDER BY `id` ASC";
    public Map<Integer, DaoMuProgressConfig> getDaoMuProgressConfig(int activityId) {
        Map<Integer, DaoMuProgressConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getDaoMuProgressSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                DaoMuProgressConfig info = new DaoMuProgressConfig();
                info.setActivityId(rs.getInt("activityId"));
                info.setId(rs.getInt("id"));
                info.setProgressValue(rs.getInt("progressValue"));
                info.setRewards(rs.getString("rewards"));
                map.put(info.getId(), info);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * 摸金等级配置
     */
    private static String getDaoMuCaptainSql = "select * from `t_s_activity_daomu_captain` where `activityId`= ? ORDER BY `id` ASC";
    public Map<Integer, DaoMuCaptainConfig> getDaoMuCaptainConfig(int activityId) {
        Map<Integer, DaoMuCaptainConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getDaoMuCaptainSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                DaoMuCaptainConfig info = new DaoMuCaptainConfig();
                info.setActivityId(rs.getInt("activityId"));
                info.setId(rs.getInt("id"));
                info.setLevel(rs.getInt("level"));
                info.setCost(rs.getInt("cost"));
                info.setPvpBasePara(rs.getString("pvpBasePara"));
                info.setPvpArmsType(rs.getInt("pvpArmsType"));
                map.put(info.getLevel(), info);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * PVE配置
     */
    private static String getDaoMuPvpSql = "select * from `t_s_activity_daomu_pvp` where `activityId`= ? ORDER BY `id` ASC";
    public Map<Integer, DaoMuPvpConfig> getDaoMuPvpConfig(int activityId) {
        Map<Integer, DaoMuPvpConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getDaoMuPvpSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                DaoMuPvpConfig info = new DaoMuPvpConfig();
                info.setActivityId(rs.getInt("activityId"));
                info.setId(rs.getInt("id"));
                info.setHome(rs.getString("home"));
                info.setBirthPoint(rs.getInt("birthPoint"));
                info.setPeople(rs.getInt("people"));
                info.setBoxNum(rs.getInt("boxNum"));
                info.setBoxWeights(rs.getString("boxWeights"));
                info.setBoxHits(rs.getInt("boxHits"));
                info.setBoxRefreshTime(rs.getInt("boxRefreshTime"));
                info.setMobsId(rs.getString("mobsId"));
                info.setUpgradeNeedLevel(rs.getInt("upgradeNeedLevel"));
                info.setUpgradeNeedTime(rs.getInt("upgradeNeedTime"));
                info.setCollapseCondPeople(rs.getInt("collapseCondPeople"));
                info.setCollapseCondTime(rs.getInt("collapseCondTime"));
                info.setShrinkCircle(rs.getString("shrinkCircle"));
                info.setShrinkCircleHarm(rs.getString("shrinkCircleHarm"));
                info.setDisuse(rs.getInt("disuse"));
                map.put(info.getId(), info);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * PVE技能配置
     */
    private static String getDaoMuPvpSkillSql = "select * from `t_s_activity_daomu_pvp_skill` where `activityId`= ? ORDER BY `id` ASC";
    public Map<Integer, DaoMuPvpSkillConfig> getDaoMuPvpSkillConfig(int activityId) {
        Map<Integer, DaoMuPvpSkillConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getDaoMuPvpSkillSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                DaoMuPvpSkillConfig info = new DaoMuPvpSkillConfig();
                info.setActivityId(rs.getInt("activityId"));
                info.setId(rs.getInt("id"));
                info.setSkillId(rs.getInt("skillId"));
                info.setType(rs.getInt("type"));
                info.setLevel(rs.getInt("level"));
                info.setName(rs.getString("name"));
                info.setDesc(rs.getString("desc"));
                info.setIcon(rs.getInt("icon"));
                info.setSkillPara(rs.getString("skillPara"));
                map.put(info.getId(), info);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * PVP榜单积分
     */
    private static String getDaoMuPvpRankSql = "select * from `t_s_activity_daomu_pvp_rank` where `activityId`= ? ORDER BY `id` ASC";
    public Map<Integer, DaoMuPvpRankConfig> getDaoMuPvpRankConfig(int activityId) {
        Map<Integer, DaoMuPvpRankConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getDaoMuPvpRankSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                DaoMuPvpRankConfig info = new DaoMuPvpRankConfig();
                info.setActivityId(rs.getInt("activityId"));
                info.setId(rs.getInt("id"));
                info.setRound(rs.getInt("round"));
                info.setRank(rs.getInt("rank"));
                info.setScore(rs.getLong("score"));
                map.put(info.getId(), info);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }
}
